package com.znsd.study.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.znsd.entitys.BlogsInfo;
import com.znsd.stu.dao.UserDao;
import com.znsd.study.dao.BlogsDao;
import com.znsd.study.dao.SpecialtyDao;
import com.znsd.study.service.BlogService;

@Service
public class BlogServiceImpl implements BlogService {
	
	@Autowired
	private UserDao userDao;
	@Autowired
	private BlogsDao blogsDao;
	@Autowired
	private SpecialtyDao specialtyDao;
	
	@Override
	public int addBolgs(String title, String blogs, String type, String state,String user_id) {
		BlogsInfo bl=new BlogsInfo();
		bl.setBlogs_title(title);
		bl.setUser_id(userDao.checkId(Integer.parseInt(user_id)));
		bl.setBlogs_content(blogs);
		bl.setBlogs_createtime(new Date());
		bl.setBlogs_state(Integer.parseInt(state));
		bl.setSpecialty(specialtyDao.queryOne(Integer.parseInt(type)));
		System.out.println(state+"state__________________________________________");
		return blogsDao.addBolgs(bl);
	}

	@Override
	public List<BlogsInfo> queryAll(String blogs_state,String user_id,String search ,int page) {
		List<BlogsInfo> list = blogsDao.queryAll(blogs_state,user_id,search,page);
		return list;
	}

	@Override
	public long queryCount() {
		return blogsDao.queryCount();
	}

	@Override
	public BlogsInfo queryOne(String id) {
		return blogsDao.queryOne(Integer.parseInt(id));
	}

	@Override
	public int updateDz(BlogsInfo blogs) {
		return blogsDao.updateDz(blogs);
	}

	@Override
	public int delBlogs(String id) {
		return blogsDao.delBlogs(Integer.parseInt(id));
	}
	
	
}
